local shichong = fk.CreateSkill {
  name = "shichong",
}

shichong:addEffect(fk.TargetSpecified, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.tos and #data.tos == 1 and
        data.to ~= player and not data.to:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      local to = data.to
      local card =room:askToCards(to,
        { min_num = 1, max_num = 1, include_equip = false, skill_name = self.name, cancelable = true, pattern = ".", prompt =
        "#shichong-card:" .. player.id })
      if #card > 0 then
        event:setCostData(self, { cards = card })
        return true
      end
    else
      if room:askToSkillInvoke(player,{skill_name=self.name,prompt="#shichong-invoke::" .. data.to.id}) then
        event:setCostData(self, { tos = { data.to } })
        return true;
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room

    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      local to = data.to
      
      local card = room:askToChooseCard(player,{target=to,flag="h",skill_name=self.name})
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player)
    else
      room:moveCardTo(event:getCostData(self).cards, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false,
        data.to)
    end
  end,
})

shichong.switch_skill_name= "shichong"

return shichong
